<template>
  <div class="app-container">
    <form-header />
    <el-form ref="form" :model="form" :rules="rules" label-width="140px">
      <el-form-item label="名称" prop="labelName">
        <el-input v-model="form.labelName" clearable />
      </el-form-item>
      <el-form-item label="是否启用">
        <el-switch v-model="form.status" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { courseLabelAdd } from '@/api/course'
export default {
  name: 'CourseLabelAdd',
  data() {
    return {
      rules: {
        labelName: [{ required: true, trigger: 'blur', validator: this.g.checkInputIsEmpty }]
      },
      form: {
        labelName: '',
        status: 0
      }
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.form.status = this.form.status ? '1' : '0'
          courseLabelAdd(this.form).then(response => {
            console.log(response)
            this.$message({ message: '提交成功', type: 'success' })
            this.$router.push({ name: 'CourseLabelList' })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

